package linwen.wang.guava.eventbus;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @author : linwen
 * @date : 下午10:47 2021/11/4
 */
@Component
@Slf4j
public class EventPublisher {

    @Autowired
    private EventBus eventBus;

    @Autowired
    private AsyncEventBus asyncEventBus;

    /**
     * 同步发送消息
     *
     * */
    public void publishMessage(Message message){
        log.info("start send message......");
        eventBus.post(message);
    }

    /**
     * 异步发送消息
     *
     * */
    public void asyncPublishMessage(Message message){
        log.info("async send message......");
        asyncEventBus.post(message);
    }
}
